package com.xiaoyu.lanling.util;

import android.content.Context;

import com.xiaoyu.base.app.AppContext;

import java.io.File;

import in.srain.cube.cache.DiskFileUtils;

public class FileCreateUtils {

    private static final int CREATE_IMAGE = 1;
    private static final int CREATE_GIF = 2;
    private static final int CREATE_VIDEO = 3;
    private static final int CREATE_AUDIO = 4;

    public static File createImageFile() {
        return createFile(CREATE_IMAGE);
    }

    public static File createGifFile() {
        return createFile(CREATE_GIF);
    }

    public static File createVideoFile() {
        return createFile(CREATE_VIDEO);
    }

    public static File createAudioFile() {
        return createFile(CREATE_AUDIO);
    }

    private static File createFile(int mode) {
        File file = null;
        Context context = AppContext.getContext();
        switch (mode) {
            case CREATE_IMAGE:
                file = new File(DiskFileUtils.wantFilesPath(context, true)
                        + "/Image/" + "ll_" + System.currentTimeMillis() + ".jpeg");
                break;
            case CREATE_GIF:
                file = new File(DiskFileUtils.wantFilesPath(context, true)
                        + "/Gif/" + "ll_" + System.currentTimeMillis() + ".gif");
                break;
            case CREATE_VIDEO:
                file = new File(DiskFileUtils.wantFilesPath(context, true)
                        + "/Video/" + "ll_" + System.currentTimeMillis() + ".mp4");
                break;
            case CREATE_AUDIO:
                file = new File(DiskFileUtils.wantFilesPath(context, true)
                        + "/Audio/" + "ll_" + System.currentTimeMillis() + ".mp3");
                break;
        }
        if (file != null && !file.getParentFile().exists()) {
            file.getParentFile().mkdirs();
        }
        return file;
    }
}
